package com.example.fx.utils

import android.content.Context
import com.alibaba.android.arouter.facade.Postcard
import com.alibaba.android.arouter.facade.annotation.Interceptor
import com.alibaba.android.arouter.facade.callback.InterceptorCallback
import com.alibaba.android.arouter.facade.template.IInterceptor
import com.alibaba.android.arouter.launcher.ARouter
import com.blankj.utilcode.util.SPUtils
@Interceptor(priority = 1)
class LoginInterceptor:IInterceptor {
    override fun init(context: Context?) {
    }

    override fun process(postcard: Postcard?, callback: InterceptorCallback?) {
        //判断当SP中有值时，任意路径可访问，当路径为Login的路径可访问    除这两种情况外其他均需跳转到登录界面
        if(SPUtils.getInstance().getString("token").isNotEmpty()||"/app/LoginActivity".equals(postcard?.path)){
            callback?.onContinue(postcard)
        }else{
            ARouter.getInstance().build("/app/LoginActivity").navigation()
        }
    }
}